import path, { resolve } from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import svgLoader from 'vite-svg-loader';
import qiankun from 'vite-plugin-qiankun';
// import configArcoStyleImportPlugin from './plugin/arcoStyleImport';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import config from '../package.json';

export default defineConfig({
  plugins: [
    vue(),
    svgLoader({ svgoConfig: {} }),
    qiankun(config.name, { useDevMode: true }),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), '../src/assets/svg')],
      // 指定symbolId格式
      symbolId: 'icon-[dir]-[name]',
    }),
  ],
  server: {
    host: '0.0.0.0',
    port: 10008,
    cors: true,
    // 是否开启 https
    https: false,
    hmr: {
      overlay: false,
    },
    proxy: {
      '/api/platform': {
        target: 'http://console.cloud.test.net/api/platform',
        // target: 'http://10.176.118.58:8100',
        rewrite: (path) => path.replace(new RegExp(`^/api/platform`), ''),
        changeOrigin: true,
      },
    },
  },
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, '../src'),
      },
      {
        find: 'common',
        replacement: resolve(__dirname, '../src/views/common'),
      }
    ],
    extensions: ['.ts', '.js'],
  },
  define: {
    'process.env': {},
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${resolve(
            'src/assets/style/breakpoint.less'
          )}"; @import (reference) "${resolve('src/components/wflow/style/wflow-theme.less')}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
});
